<template>
  <page-layout :noToolbar="true">
    <div class="card-header">意见反馈</div>
    <el-card class="box-card">
      <!--<el-card class="box-card">-->
        <!--<el-form ref="searchSuggestionCondition" :model="searchSuggestionCondition" label-width="80px" inline>-->
          <!--<el-form-item label="姓名">-->
            <!--<el-input v-model="searchSuggestionCondition.name" style="width: 300px;"/>-->
          <!--</el-form-item>-->
          <!--<el-form-item>-->
            <!--<el-button type="primary" @click="refresh(1)">查询</el-button>-->
          <!--</el-form-item>-->
        <!--</el-form>-->
      <!--</el-card>-->
          <el-card class="box-card">
            <el-table
              :data="suggestionList.content" border stripe
              style="width: 100%">
              <el-table-column
                prop="id"
                label="编号"
                width="55">
              </el-table-column>
              <el-table-column prop="name" label="反馈人">
              </el-table-column>
              <el-table-column prop="contactphone" label="手机号" ></el-table-column>
              <el-table-column prop="createTime" label="反馈时间" ></el-table-column>
              <el-table-column
                prop="source"
                label="来源">
              </el-table-column>
              <el-table-column
                prop="suggestion"
                label="意见">
                <template slot-scope="scope">
                    <el-button type="text"  @click="seeSuggestionDetail(scope.row)">查看</el-button>
                </template>
              </el-table-column>
              <el-table-column
                prop="remark"
                label="备注">
              </el-table-column>

              <el-table-column
                prop="status"
                label="状态">
                <template slot-scope="scope">
                    <span>{{scope.row.status|keyText('SuggestionStatus')}}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="120">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" v-if="scope.row.status===0"  @click="editSuggestion(scope.row)">处理</el-button>
                  <el-button size="mini" type="text" v-if="scope.row.status===0"  @click="deleteSuggestion(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="mt10">
              <el-pagination
                background
                layout="prev, pager, next"
                :total="suggestionList.totalElements"
                :page-size="suggestionList.size"
                :current-page.sync="currentSuggestionPage" @current-change="getPageChange">
              </el-pagination>
            </div>
          </el-card>
    </el-card>

    <el-dialog :visible.sync="showEditor" title="处理 意见反馈" width="50%">
        <el-form >
          <el-form-item label="备注">
            <el-input type="textarea" v-model="addForm.content"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="save">保存</el-button>
            <el-button @click="back">返回</el-button>
          </el-form-item>
        </el-form>
    </el-dialog>
    <el-dialog :visible.sync="showDetail" title="意见详情" width="50%">
      <el-form >
        <el-form-item>
          <html-content :contentHtml="suggestionDetail.suggestion"></html-content>
        </el-form-item>
        <el-form-item>
          <el-button @click="showDetail=false">返回</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </page-layout>
</template>
<script>
import PageLayout from "@/components/page-layout";
import { mapGetters } from "vuex";
import Status from "@/libs/status";
import HtmlContent from "@/components/html-content";
export default {
  created() {
    this.refresh();
  },
  mounted() {},
  data() {
    return {
      currentSuggestionPage: 1,
      showEditor: false,
      showDetail: false,
      suggestionDetail: {},
      StateTypes: Status.StateTypes,
      addForm: { content: "" }
    };
  },
  computed: {
    ...mapGetters({
      suggestionList: "suggestionList",
      currentSuggestion: "currentSuggestion",
      searchSuggestionCondition: "searchSuggestionCondition"
    })
  },
  methods: {
    seeSuggestionDetail(row) {
      this.showDetail = true;
      this.suggestionDetail = row;
    },
    getPageChange(val) {
      var tem = Object.assign(
        { pageIndex: val - 1 },
        this.searchSuggestionCondition
      );
      this.$store.dispatch("getSuggestionPageS", tem).then(ret => {});
    },
    refresh() {
      this.getPageChange(1);
    },
    back() {
      this.showEditor = false;
      this.refresh();
    },
    save() {
      var tem = this.currentSuggestion;
      tem.status = 1;
      tem.remark = this.addForm.content;
      this.$store.dispatch("addOrUpdateSuggestionS", tem).then(ret => {
        this.back();
      });
    },
    editSuggestion(row) {
      this.showEditor = true;
      this.$store.dispatch("getSuggestionS", row.id).then(ret => {});
    },
    deleteSuggestion(row) {
      this.$confirm("确认删除当前意见反馈吗?", "提示", {})
        .then(() => {
          this.$store
            .dispatch("deleteSuggestionS", { id: row.id })
            .then(ret => {
              this.refresh();
              this.$notify({
                title: "删除成功",
                type: "success"
              });
            });
        })
        .catch(() => {});
    }
  },
  components: {
    PageLayout,
    HtmlContent
  }
};
</script>
<style>
</style>
